<template>
  <view class="container">
    <!-- <image class="img" :src="pageBg" mode="aspectFit" @load="onImgLoad" @error="onImgError" /> -->
  </view>
</template>

<script setup>
import { onReady, onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
const pageBg = ref('https://img0.baidu.com/it/u=1042709427,4147685100&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500');
const openId = ref('');
const isResRef = ref(false);
const loginDataRef = ref({});

onLoad(() => {
  loginDataRef.value = uni.getStorageSync('loginResult');
  onSwitchTab();
  // uni.login({
  //   provider: 'weixin',
  //   success: (res) => {
  //     console.log('获取openId: ', res); // {errMsg: "login:ok", code: "0d3k15100snN0T1d8y100hSPwO1k151i"}
  //     uni.setStorageSync('openId', res.code);
  //     onSwitchTab();
  //   },
  //   fail: (err) => {
  //     console.log('获取openid异常:', err);
  //     onSwitchTab();
  //   }
  // });
});

const onImgLoad = (event) => {
  console.log('图片加载完成：', event);
  isResRef.value = true;
  // onSwitchTab();
};

const onImgError = (event) => {
  console.log('图片加载失败：', event);
  isResRef.value = true;
  // onSwitchTab();
};

const onSwitchTab = () => {
  setTimeout(() => {
    if (loginDataRef.value && loginDataRef.value.userId) {
      uni.switchTab({
        url: '/pages/index/index'
      });
    } else
      uni.reLaunch({
        url: '/pages/login/login'
      });
  }, 3000); // 3秒后跳转到主页
};
</script>

<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  // background-color: aqua;
  .img {
    width: 100%;
    height: 100%;
  }
}
</style>
